﻿using System;
using System.IO;
using System.Text;
using System.Threading;					
using System.Diagnostics; 				
using System.Net; 						
using System.Collections.Specialized;
using System.Timers;

using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Profiles;
using Styx.Pathing;						
using Styx.WoWInternals;				
using Styx.WoWInternals.WoWObjects;		
using Styx.Plugins;						

namespace rndbuddy_csourcer
{
    public class rndbuddy_csourcer : HBPlugin
    {
        public override string Name { get { return "rndbuddy_csourcer"; } }
        public override string Author { get { return "roboto"; } }
        public override Version Version { get { return settings.version; } }
        
        public override bool WantButton { get { return true; } }
        public override void OnButtonPress() { var fr = new gui_settings(); fr.Show(); }
        public override string ButtonText { get { return "Info GUI"; } }

        public override void Pulse() { _Pulse(); }

        //crowd sourcer
        public static System.Timers.Timer crowd_col;
        public static System.Timers.Timer crowd_rep;

        //Start
        public override void Initialize()
        {
            log("Starting rndbuddy Crowdsourcer Version "+settings.version.ToString());

            rndbuddy_csourcer.log("Bringing up Collector...");
            crowd_col = new System.Timers.Timer(2000);
            crowd_col.Elapsed += new ElapsedEventHandler(crowds_ticker);
            crowd_col.Enabled = true;
            crowd_col.Start();

            rndbuddy_csourcer.log("Bringing up Reporter...");
            crowd_rep = new System.Timers.Timer(300000);
            crowd_rep.Elapsed += new ElapsedEventHandler(crowds_reporter);
            crowd_rep.Enabled = true;
            crowd_rep.Start();

            log("ready to collect");

        }

        private void _Pulse()
        {
            if (!StyxWoW.IsInGame || !StyxWoW.IsInWorld)
                return;                       
        }

        public static void log(string message)
        {
            Logging.Write(System.Windows.Media.Color.FromRgb(255,255,0),"[rndbuddy crowdsourcer] " + message);
        }

        public void crowds_ticker(object sender, ElapsedEventArgs e)
        {
            crowdsourcer.get_nodes();
        }

        public void crowds_reporter(object sender, ElapsedEventArgs e)
        {
            rndbuddy_csourcer.log("I got " + crowdsourcer.amount_of_nodes().ToString() + " Nodes nodes to Report");
            server_pipe.report_crowdsourcer_data(true);
        }
    }
}
